﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lm.Common.Auth.Token
{
    class DelayExpireTime
    {
        public void Delay(Guid tokenId)
        {
            using (var tran = new System.Transactions.TransactionScope())
            {
                if (tokenId == null)
                { throw new Exception("tokenId不能为空"); }
                int tokenExpireMinutes = Lm.Common.Auth.Config.ConfigReader.TokenExpireMinutes;
                DateTime expireTime = DateTime.Now.AddMinutes(tokenExpireMinutes);
                var helper = Lm.Common.Auth.DAL.DALFactory.Create();
                var i = helper.Update<Model.Token>(t => new Model.Token() { ExpireTime = expireTime }, t => t.Id == tokenId);
                if (i != 1)
                { throw new Exception("token续约失败"); }
                tran.Complete();
            }
        }
    }
}
